﻿using System;
using fastCSharp;

namespace diantou.web.include
{
    /// <summary>
    /// 获取收藏夹
    /// </summary>
    [fastCSharp.code.cSharp.webView(IsPage = false, IsPool = true)]
    partial class linkFavorite : currentUserView<linkFavorite>
    {
        /// <summary>
        /// 收藏夹与收藏目标项目关系
        /// </summary>
        private struct favorite
        {
            /// <summary>
            /// 收藏夹
            /// </summary>
            public diantou.dataAccess.favorite Favorite;
            /// <summary>
            /// 收藏目标项目标识
            /// </summary>
            public int LinkId;
            /// <summary>
            /// 收藏夹是否存在收藏项目
            /// </summary>
            private bool? isFavorite;
            /// <summary>
            /// 收藏夹是否存在收藏项目
            /// </summary>
            public bool IsFavorite
            {
                get
                {
                    if (isFavorite == null)
                    {
                        isFavorite = diantou.dataAccess.tcpCall.favorites.IsFavorite(Favorite.Id, LinkId);
                    }
                    return (bool)isFavorite;
                }
            }
        }
        /// <summary>
        /// 收藏夹集合
        /// </summary>
        [fastCSharp.emit.webView.clearMember]
        private favorite[] favorites;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="type"></param>
        /// <param name="linkId">收藏目标项目标识</param>
        /// <returns></returns>
        private bool loadView(diantou.dataAccess.favorite.type type, int linkId)
        {
            diantou.dataAccess.favorite[] favorites = diantou.dataAccess.clientCache.Favorite.Get(diantou.dataAccess.tcpCall.favorite.getIdsByUser(currentUser.Id, type));
            this.favorites = favorites.getArray(value => new favorite { Favorite = value, LinkId = linkId });
            return true;
        }
    }
}
